package com.qingsong.controller;

import com.mybatisflex.core.paginate.Page;
import com.qingsong.dto.SeckillDetailInsertDTO;
import com.qingsong.dto.SeckillDetailPageDTO;
import com.qingsong.dto.SeckillDetailUpdateDTO;
import com.qingsong.entity.SeckillDetail;
import com.qingsong.entity.SeckillDetail;
import com.qingsong.vo.SeckillDetailSimpleListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.qingsong.service.SeckillDetailService;

import java.util.List;

/**
 * 秒杀明细表 控制层。
 *
 * @author qingsong
 * @since 2024-12-22
 */
@Tag(name = "秒杀明细")
@RestController
@RequestMapping("/seckillDetail")
public class SeckillDetailController {

    @Autowired
    private SeckillDetailService seckillDetailService;

    @Operation(summary = "新增-单条", description = "新增一条秒杀明细记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody SeckillDetailInsertDTO dto) {
        return seckillDetailService.insert(dto);
    }

    @Operation(summary = "查询-单条", description = "按主键查询一条秒杀明细记录")
    @GetMapping("select/{id}")
    public SeckillDetail select(@PathVariable("id") Long id) {
        return seckillDetailService.select(id);
    }

    @Operation(summary = "查询-简单列表", description = "查询全部秒杀明细记录,仅返回简单信息")
    @GetMapping("simpleList")
    public List<SeckillDetailSimpleListVO> simpleList() {
        return seckillDetailService.simpleList();
    }

    @Operation(summary = "查询-分页", description = "分页查询秒杀明细记录")
    @GetMapping("page")
    public Page<SeckillDetail> page(@Validated SeckillDetailPageDTO dto) {
        return seckillDetailService.page(dto);
    }

    @Operation(summary = "修改-单条", description = "按主键修改一条秒杀明细记录")
    @PutMapping("update")
    public boolean update(@RequestBody SeckillDetailUpdateDTO dto) {
        return seckillDetailService.update(dto);
    }

    @Operation(summary = "删除-单条", description = "按主键删除一条秒杀明细记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return seckillDetailService.delete(id);
    }

    @Operation(summary = "删除-批量", description = "按主键批量删除秒杀明细记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return seckillDetailService.deleteBatch(ids);
    }

}
